#include "zmath.h"

int zmath_powoftwo(int val)
{
	if (val & (val - 1))//at least has 2 bit equal to 1!
	{
		int leftmost;

		while (val)
		{
			leftmost = val;
			val &= (val - 1);
		}

		return leftmost << 1;
	}
	else
	{
		return val == 0 ? 1 : val;
	}
}